<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑审核内容</title>
</head>
<body>
<script type="text/html" id="form">
    <input type="hidden" name="id" value="{{ d.id }}"/>
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <text title="必填项" style="color:red;">*</text>
                        内容标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" value="{{d.title}}" lay-verify="required" autocomplete="off"
                               placeholder="请输入内容标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <text style="color:red;">支持jpg、png，大小不超过5M，图片尺寸建议 5:3比例</text>
                    <label class="layui-form-label">
                        <text title="必填项" style="color:red;">*</text>
                        icon图标</label>
                    <div class="layui-input-block">
                        <div class="laytpUpload"
                             data-name="icon"
                             data-dir="xm_game/calendar2/content/icon"
                             data-accept="image"
                             data-type="ali-oss"
                             data-layVerify="required"
                             data-showChoiceBtn="false"
                             data-uploadedId="{{d.icon}}"
                             data-uploaded="{{d.icon}}"
                        ></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">内容背景颜色</label>
                    <div style="margin-left: 30px;">
                        <div id="contentColor"></div>
                        <input type="hidden" name="content_color" id="choose_color3"  value="{{d.content_color}}"/>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        <text title="必填项" style="color:red;">*</text>
                        内容</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" name="content" id="LAY_demo" lay-verify="content"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" title="视频路径">视频路径</label>
                    <div class="layui-input-block">
                        <div class="laytpUpload"
                             data-name="video_url"
                             data-accept="video"
                             data-multi="false"
                             data-uploadedId="{{d.video_url}}"
                             data-uploaded="{{d.video_url}}"
                             data-showChoiceBtn="false"
                             data-type="ali-oss"
                        ></div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <text title="必填项" style="color:red;">*</text>
                        活动时效</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input laydate"
                               id="create_time" name="time"
                               data-type="datetime" value="{{d.start_time!=null?d.start_time:''}} {{d.start_time!=null?'-':''}} {{d.end_time!=null?d.end_time:''}}" data-isRange="true"
                               placeholder="请选择活动时效时间">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" title="归属模块">
                        <text title="必填项" style="color:red;">*</text>
                        归属模块</label>
                    <div class="layui-input-inline">
                        <div class="xmSelect"
                             data-name="module_id"
                             data-sourceType="route"
                             data-source="/admin.calendar2.module/index"
                             data-params='{"search_param":{"relation_id":{"value":"{{d.relation_id}}","condition":"="},"status":{"value":"1","condition":"="}}}'
                             data-sourceTree="false"
                             data-paging="true"
                             data-valueField="id"
                             data-textField="name"
                             data-radio="true"
                             data-placeholder="请选择模块"
                             data-selected="{{d.module_id}}"
                        ></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            {{# if(d.status!=1){ }}
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" data-status="2" lay-submit=""
                    lay-filter="laytp-form">
                <i class="layui-icon layui-icon-edit"></i>
                保存
            </button>
            {{# if(facade.hasAuth("/admin.calendar2.grabContent/submit?game_id="+d.relation_id)){ }}
            <button type="submit" class="laytp-btn laytp-btn-success laytp-btn-sm" data-status="1" lay-submit=""
                    lay-filter="laytp-form">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            {{# } }}
            {{# } }}


        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form"></form>
<script>
    if (localStorage.getItem("staticDomain")) {
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
    } else {
        document.write("<link rel='stylesheet' href='/static/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
    }
</script>
<script>
    layui.use(['laytp', 'xmSelect', 'layedit', 'form','colorpicker'], function () {
        let $ = layui.jquery;
        let form = layui.form;
        var layedit = layui.layedit;
        let colorpicker = layui.colorpicker;

        layedit.set({
            uploadImage: {
                url: "/admin.common/editUpload"
                , type: ''//默认post
            },
            uploadVideo: {
                url: "/admin.common/editUpload"
                ,accept:"m3u8"
                , type: ''//默认post
            }
        })

        //获取参数ID
        var id = facade.getUrlParam('id');
        if (!id) {
            facade.error('参数ID不能为空');
            return false;
        }

        //获取数据，渲染到对应的节点上
        facade.ajax({
            route: "/admin.calendar2.grabContent/info",
            data: {id: id},
            successAlert: false,
            showLoading: true
        }).done(function (res) {
            if (res.code === 0) {
                layui.laytpl($("#form").html()).render(res.data, function (string) {
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                    //常规使用
                    colorpicker.render({
                        elem: '#contentColor' //绑定元素.
                        ,color: res.data.content_color
                        ,change: function(color){ //颜色改变的回调
                            $('#choose_color3').val(color);
                        }
                    });
                });

                var index = layedit.build('LAY_demo', {
                    tool: [
                        'strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right', '|', 'image', 'video'
                    ],
                    height: 500,
                });

                form.verify({
                    content: function (value) {
                        return layedit.sync(index);
                    },
                });

                layedit.setContent(index, res.data.content);
            }
        });

        form.on('submit(laytp-form)', function (data) {
            var btnAnim = layui.button.load({elem: $(this)});
            data.field.status = $(this).attr("data-status")
            facade.ajax({
                route: '/admin.calendar2.grabContent/edit',
                data: data.field
            }).done(function (res) {
                if (res.code === 0) {
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("laytp-table");
                }
                btnAnim.stop();
            }).fail(function () {
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>